<?php
    class Model_mahasiswa extends CI_Model{
        public $nim='';
        public $nama='';
        public $fakultas='';
        public $prodi='';
        public $angkatan='';
        public $asal='';
        public $semester='';
        public $slotbeasiswa='';
        public $statustunda='';
        public $spp='';
        
        function __construct() {
            parent::__construct();
        }
        function insert($param=''){
                
            if ($param==''){
            $data = array(
                    'nim'=>$this->nim,
                    'nama'=>$this->nama,
                    'fakultas'=>$this->fakultas,
                    'prodi'=>$this->prodi,
                    'angkatan'=>$this->angkatan,
                    'asal'=>$this->asal,
                    'semester'=>$this->semester,
                    'slotbeasiswa'=>$this->slotbeasiswa,
                    'statustunda'=>$this->statustunda,
                    'spp'=>$this->spp
                );
            }else{
                $data=$param;
            }
            return $this->db->insert('mahasiswa',$data);
        }
        function select_mahasiswa_fakultas($kondisi)
        {
            $result = $this->db->get_where("mahasiswa",$kondisi);
            return $result->result_array();
        }


        function select($kondisi='',$like='',$limit='',$offset=1){
            if ($offset=="" || $offset==0)
                $offset=1;
            if($like!=''){
                $this->db->like($like);
            }
            $query = $this->db->get_where("mahasiswa",$kondisi,$limit,(($offset-1)*$limit));
            
            //die();
            return $query->result_array();
        }
        function isnext($kondisi='',$like='',$limit='',$offset=''){
            if($like!='')
            $this->db->like($like);
            $query = $this->db->get_where("mahasiswa",$kondisi,$limit,($offset*$limit));
            return ($query->num_rows() > 0);
        }
        function isback($offset){
            if($offset==1)
                return false;
            return true;
        }

        function curPageURL() {
         $pageURL = 'http';
//         if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
         $pageURL .= "://";
         if ($_SERVER["SERVER_PORT"] != "80") {
          $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
         } else {
          $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
         }
         return $pageURL;
        }

        function count()
        {
            $query = $this->db->query("SELECT COUNT(idmhs) AS jumlah FROM mahasiswa");
            $row = $query->result_array();
            return $row[0]['jumlah'];
        }
        function query($query){
            $result = $this->db->query($query);
            return $result;
        }
        function update($nim,$data=''){
            if($data==''){
               $data = array(
                'nim'=>$this->nim,
                'nama'=>$this->nama,
                'fakultas'=>$this->fakultas,
                'prodi'=>$this->prodi,
                'angkatan'=>$this->angkatan,
                'asal'=>$this->asal,
                'semester'=>$this->semester,
                'slotbeasiswa'=>$this->slotbeasiswa,
                'statustunda'=>$this->statustunda,
                'spp'=>$this->spp
               ); 
            }
            $this->db->where('nim', $nim);
            $this->db->update('mahasiswa', $data); 
        }
        
        function updatespp($nim,$data=''){
            if($data==''){
               $data = array(
                'spp'=>$this->spp
               ); 
            }
            $this->db->where('nim', $nim);
            $this->db->update('mahasiswa', $data); 
        }
        
        function delete($nim){
            $this->db->where('nim', $nim);
            $this->db->delete('mahasiswa');
        }

        function tampil_list_mahasiswa($id)
        {
            $result = $this->db->query("SELECT nama,nim,fakultas,prodi,tanggal,donasi.semester AS smstr FROM donasi INNER JOIN mahasiswa ON (donasi.idmhs=mahasiswa.idmhs) WHERE iddonatur = $id");
            return $result->result_array();
        }

//        function select_cari($angkatan,$like)
//        {
//            $null = array();
//            if ($like!=null)
//                $this->db->like($like);
//            if($angkatan!=null && $status!='all')
//                $this->db->where('status',$status);
//            $query=$this->db->get('mahasiswa');
//            return $query->result_array();
//        }
    }
?>
